//
//  NvDraftTableViewCell.m
//  NvSellerShow
//
//  Created by Meicam on 2017/3/20.
//  Copyright © 2017年 Meicam. All rights reserved.
//

#import "NvDraftTableViewCell.h"

@implementation NvDraftTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellPressed)]];
}

- (void)cellPressed {
    if(self.isEditing) {
        [self setCheckedState:!self.isSelected];
        if(self.delegate != nil && [self.delegate respondsToSelector:@selector(draftTableViewCell:updateCheckState:withDraftModel:)] ==YES){
            [self.delegate draftTableViewCell:self updateCheckState:self.isSelected withDraftModel:self.draftModel];
        }
    }
    else {
        if(self.delegate != nil && [self.delegate respondsToSelector:@selector(draftTableViewCell:openDraftModel:)] ==YES){
            [self.delegate draftTableViewCell:self openDraftModel:self.draftModel];
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)fillDraftModel:(NvDraftModel *)model {
    self.draftModel = model;
    self.draftTypeLabel.text = model.fileName;
    self.draftCreatedTimeLabel.text = model.fileDuration;
    [self.thumbImageView setImage:model.coverImage];
}

- (void)setEditingMode:(BOOL)isEditing {
    self.isEditing = isEditing;
    if(self.isEditing) {
        self.markImageWidthConstraint.constant = 43;
    }
    else {
        self.markImageWidthConstraint.constant = 0;
    }
}
- (void)setCheckedState:(BOOL)isChecked {
    self.isSelected = isChecked;
    [self updateCheckState];
}

- (void)updateCheckState {
    if(self.isSelected){
        [self.markImageView setImage:[UIImage imageFromBundle:@"check_icon_left"]];
    }
    else {
        [self.markImageView setImage:[UIImage imageFromBundle:@"check_icon_left_a"]];
    }
}

@end
